﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class FormLaySprinklerByRectangle : System.Windows.Forms.Form
	{
		public int CurrentBtn
		{
			get
			{
				return this.currentBtn;
			}
		}

		public FamilySymbol Fsymbol { get; set; }

		public FormLaySprinklerByRectangle(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Location = new System.Drawing.Point(100, 100);
			base.Icon = Resource.YArchitechIcon;
			this.doc = doc;
			this.InitCurrentProject();
			this.btnHy.BackColor = System.Drawing.Color.White;
			this.currentBtn = 0;
			this.btnproj.BackColor = System.Drawing.Color.Transparent;
			this.panelHy.Visible = true;
			this.panelProj.Visible = false;
			this.LaySettingInitJuXing();
			this.InitCmbDanger();
		}

		private void InitCurrentProject()
		{
			this.tvwProject.Nodes.Add("喷头");
			HyProjectFamily.BingTvwFamilysTwoLevel(HyProjectFamily.GetFamilys(BuiltInCategory.OST_Sprinklers, this.doc), this.tvwProject);
		}

		private void picbox_Click(object sender, EventArgs e)
		{
			this.name = this.lbfname.Text;
			FormChooseSprinkler formChooseSprinkler = new FormChooseSprinkler(this.name, this.listInfos);
			formChooseSprinkler.Text = "选择喷头";
			formChooseSprinkler.Owner = this;
			if (formChooseSprinkler.ShowDialog() == DialogResult.OK && this.name != formChooseSprinkler.ImageName && formChooseSprinkler.ImageName != "")
			{
				this.name = formChooseSprinkler.ImageName;
				this.lbfname.Text = this.name;
				foreach (ListItem listItem in this.listInfos)
				{
					if (listItem.Name == this.name)
					{
						this.id = int.Parse(listItem.Tag.ToString());
						break;
					}
				}
			}
		}

		private void FormLaySprinklerHead_Load(object sender, EventArgs e)
		{
			this.Initcbbeishu();
			this.initParameterSetting();
			switch (this.familyCategory)
			{
			case 1:
				this.rbtUp.Checked = true;
				break;
			case 2:
				this.rbtDown.Checked = true;
				break;
			case 4:
				this.rbtShuimu.Checked = true;
				break;
			case 5:
				this.rbtUpDown.Checked = true;
				break;
			}
			switch (this.familyConnStyle)
			{
			case 1:
				this.rdoHorizontal.Checked = true;
				break;
			case 2:
				this.rdoVertical.Checked = true;
				break;
			case 3:
				this.rdoNone.Checked = true;
				break;
			}
			this.GetfamilyNameFromData();
			this.lbfname.Text = this.familyName;
			if (this.listname.Count > 0)
			{
				foreach (ListItem listItem in this.listname)
				{
					if (listItem.Name == this.name)
					{
						this.id = int.Parse(listItem.Tag.ToString());
						break;
					}
				}
				if (this.id == 0)
				{
					this.id = 1;
				}
			}
			if (this.lbSymbol.Items.Count > 0)
			{
				this.lbSymbol.SelectedItem = this.familySymbol;
			}
			this.UpdataCheckStatic();
		}

		private void Initcbbeishu()
		{
			this.cbJianju.Items.Clear();
			this.cbJianju.Items.Add("50");
			this.cbJianju.Items.Add("100");
		}

		private void GetSprinklerPara()
		{
			if (!(this.tbLevel.Text.Trim() != "") || !(this.tbRadius.Text.Trim() != "") || !(this.tbK.Text.Trim() != "") || !(this.lbSymbol.SelectedItem.ToString() != "") || !(this.cbJianju.Text.Trim() != "") || !(this.tbDistance.Text.Trim() != "") || this.id <= 0)
			{
				YJKMessageBox.Show("参数都不能为空");
				return;
			}
			if (double.Parse(this.tbRadius.Text.Trim()) == 0.0)
			{
				YJKMessageBox.Show("喷淋半径不能为0");
				return;
			}
			if (!Regex.IsMatch(this.cbJianju.Text, "^\\d+$"))
			{
				YJKMessageBox.Show("倍数必须为非负整数");
				this.cbJianju.Focus();
				return;
			}
			if (double.Parse(this.tbDistance.Text.Trim()) <= 0.0 && !this.rbtUpDown.Checked)
			{
				YJKMessageBox.Show("喷头与支管间距应大于0");
				this.tbDistance.Focus();
				return;
			}
			this.isParking = this.chkParking.Checked;
			this.sprinklersPara = new SprinklersParam();
			this.sprinklersPara.OffSet = double.Parse(this.tbLevel.Text.Trim());
			this.sprinklersPara.Radius = double.Parse(this.tbRadius.Text.Trim());
			this.sprinklersPara.Range = this.checkBox.Checked;
			this.sprinklersPara.ThreePoint = this.chkThreePoint.Checked;
			this.sprinklersPara.Kratio = double.Parse(this.tbK.Text.Trim());
			this.sprinklersPara.SymbolName = this.lbSymbol.SelectedItem.ToString();
			this.sprinklersPara.BeiShu = int.Parse(this.cbJianju.Text.ToString());
			this.sprinklersPara.PipeDistance = double.Parse(this.tbDistance.Text.Trim());
			this.sprinklersPara.Id = this.id;
			this.sprinklersPara.PipeType = this.cbxPipeType.SelectedIndex;
			this.sprinklersPara.PipingSystemType = this.cmbSystemType.SelectedIndex;
			this.sprinklersPara.Danger = this.cmbDanger.Text.Trim();
		}

		private void initParameterSetting()
		{
			UserSetting userSetting = new UserSetting();
			if (userSetting.GetValue("sprinklersRetangle", "familyCategory") != "")
			{
				this.familyCategory = int.Parse(userSetting.GetValue("sprinklersRetangle", "familyCategory"));
			}
			else
			{
				this.familyCategory = 1;
			}
			this.familyName = userSetting.GetValue("sprinklersRetangle", "familyName");
			this.familySymbol = userSetting.GetValue("sprinklersRetangle", "familySymbol");
			if (userSetting.GetValue("sprinklersRetangle", "familyConnStyle") != "")
			{
				this.familyConnStyle = int.Parse(userSetting.GetValue("sprinklersRetangle", "familyConnStyle"));
			}
			else
			{
				this.familyConnStyle = 1;
			}
			this.tbLevel.Text = userSetting.GetValue("sprinklersRetangle", "offset");
			this.cbJianju.Text = userSetting.GetValue("sprinklersRetangle", "beishu");
			this.tbDistance.Text = userSetting.GetValue("sprinklersRetangle", "distance");
			this.hytbRowAngle.Text = userSetting.GetValue("sprinklersRetangle", "rowAngle");
			if (this.hytbRowAngle.Text == "")
			{
				this.hytbRowAngle.Text = "0";
			}
			this.chkBeams.Checked = false;
			if (userSetting.GetValue("sprinklersRetangle", "chkParking") != "" && userSetting.GetValue("sprinklersRetangle", "chkParking").Equals("True"))
			{
				this.chkParking.Checked = true;
			}
			else
			{
				this.chkParking.Checked = false;
			}
			this.chkColumns.Checked = false;
			try
			{
				this.checkBox.Checked = Convert.ToBoolean(userSetting.GetValue("sprinklersRetangle", "range"));
				this.chkThreePoint.Checked = Convert.ToBoolean(userSetting.GetValue("sprinklersRetangle", "threePoint"));
				int num = int.Parse(userSetting.GetValue("sprinklersRetangle", "pipeType"));
				if (num > this.cbxPipeType.Items.Count)
				{
					this.cbxPipeType.SelectedIndex = 0;
				}
				else
				{
					this.cbxPipeType.SelectedIndex = num;
				}
				int num2 = int.Parse(userSetting.GetValue("sprinklersRetangle", "systemType"));
				if (num2 > this.cmbSystemType.Items.Count)
				{
					this.cmbSystemType.SelectedIndex = 0;
				}
				else
				{
					this.cmbSystemType.SelectedIndex = num2;
				}
				this.cmbDanger.Text = userSetting.GetValue("sprinklersRetangle", "danger");
			}
			catch (Exception)
			{
			}
		}

		private void UserSettingWrite()
		{
			this.tbLevel.Text = StringTools.RemoveZero(this.tbLevel.Text.Trim());
			this.cbJianju.Text = StringTools.RemoveZero(this.cbJianju.Text.Trim());
			try
			{
				UserSetting userSetting = new UserSetting();
				userSetting.WriteValue("sprinklersRetangle", "familyCategory", this.familyCategory.ToString());
				userSetting.WriteValue("sprinklersRetangle", "familyConnStyle", this.familyConnStyle.ToString());
				userSetting.WriteValue("sprinklersRetangle", "familyName", this.lbfname.Text.Trim());
				userSetting.WriteValue("sprinklersRetangle", "familySymbol", this.lbSymbol.SelectedItem.ToString());
				userSetting.WriteValue("sprinklersRetangle", "offset", this.tbLevel.Text);
				userSetting.WriteValue("sprinklersRetangle", "range", this.checkBox.Checked.ToString());
				userSetting.WriteValue("sprinklersRetangle", "beishu", this.cbJianju.Text);
				userSetting.WriteValue("sprinklersRetangle", "distance", this.tbDistance.Text);
				userSetting.WriteValue("sprinklersRetangle", "threePoint", this.chkThreePoint.Checked.ToString());
				userSetting.WriteValue("sprinklersRetangle", "pipeType", this.cbxPipeType.SelectedIndex.ToString());
				userSetting.WriteValue("sprinklersRetangle", "systemType", this.cmbSystemType.SelectedIndex.ToString());
				userSetting.WriteValue("sprinklersRetangle", "rowAngle", this.hytbRowAngle.Text.Trim());
				userSetting.WriteValue("sprinklersRetangle", "chkBeams", this.chkBeams.Checked.ToString());
				userSetting.WriteValue("sprinklersRetangle", "chkParking", this.chkParking.Checked.ToString());
				userSetting.WriteValue("sprinklersRetangle", "chkColumns", this.chkColumns.Checked.ToString());
				userSetting.WriteValue("sprinklersRetangle", "danger", this.cmbDanger.Text);
				this.SaveParasFofDB();
			}
			catch (Exception)
			{
			}
		}

		private void SaveParasFofDB()
		{
			List<ListItem> list = new List<ListItem>();
			list.Add(new ListItem("RadiuDiameter", this.sprinklersPara.Radius.ToString()));
			list.Add(new ListItem("KCoefficient", this.sprinklersPara.Kratio.ToString()));
			if (!this.sfdr.SetInfoById("Sprinkler", this.sprinklersPara.Id, list))
			{
				YJKMessageBox.Show("保存数据失败");
			}
		}

		private void rbtUp_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtUp.Checked)
			{
				this.familyCategory = 1;
				this.GetfamilyNameFromData();
				this.lbfname.Text = this.listname[0].Name;
				if (!this.rdoNone.Checked)
				{
					this.tbDistance.Enabled = true;
				}
			}
		}

		private void rbtDown_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtDown.Checked)
			{
				this.familyCategory = 2;
				this.GetfamilyNameFromData();
				this.lbfname.Text = this.listname[0].Name;
				if (!this.rdoNone.Checked)
				{
					this.tbDistance.Enabled = true;
				}
			}
		}

		private void rbtCe_CheckedChanged(object sender, EventArgs e)
		{
		}

		private void rbtShuimu_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtShuimu.Checked)
			{
				this.familyCategory = 4;
				this.GetfamilyNameFromData();
				this.lbfname.Text = this.listname[0].Name;
				if (!this.rdoNone.Checked)
				{
					this.tbDistance.Enabled = true;
				}
			}
		}

		private void rbtUpDown_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtUpDown.Checked)
			{
				this.familyCategory = 5;
				this.GetfamilyNameFromData();
				this.lbfname.Text = this.listname[0].Name;
				this.tbDistance.Enabled = false;
			}
		}

		private void GetfamilyNameFromData()
		{
			this.listname = this.sfdr.GetAllName("Sprinkler", this.familyCategory);
			this.listInfos = this.sfdr.GetAllNameAndImage("Sprinkler", this.familyCategory);
		}

		private void UptadaFamilySybol(string szData)
		{
			this.lbSymbol.Items.Clear();
			foreach (string text in szData.Split(new char[]
			{
				';',
				',',
				'，'
			}))
			{
				if (text.Trim() != "")
				{
					this.lbSymbol.Items.Add(text);
				}
			}
			if (this.lbSymbol.Items != null && this.lbSymbol.Items.Count > 0)
			{
				this.lbSymbol.SelectedIndex = 0;
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void FormLaySprinklerHead_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.UserSettingWrite();
		}

		private void btnJuXing_Click(object sender, EventArgs e)
		{
			if (this.hytbRowAngle.Text.Trim() == "")
			{
				YJKMessageBox.Information("行向角参数不能为空！");
				this.hytbRowAngle.Focus();
				return;
			}
			this.GetRectLayParas();
			if (this.chkThreePoint.Checked)
			{
				this.isThreePointLay = true;
			}
			this.layTerminalType = 3;
			this.GetSprinklerPara();
			if (!this.rdoLimitDistance2.Checked)
			{
				this.isBeams = false;
				this.isParking = false;
				this.isAvoidColumns = false;
			}
			if (this.sprinklersPara != null && this.GetFormDataForJuXing())
			{
				base.DialogResult = DialogResult.OK;
			}
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.layTerminalType = 5;
			this.GetSprinklerPara();
			if (!this.rdoLimitDistance2.Checked)
			{
				this.isBeams = false;
				this.isParking = false;
				this.isAvoidColumns = false;
			}
			if (this.sprinklersPara != null && this.GetFormDataForJuXing())
			{
				base.DialogResult = DialogResult.OK;
			}
		}

		private void lbfname_TextChanged(object sender, EventArgs e)
		{
			this.LbfnameTextChanged();
		}

		private void LbfnameTextChanged()
		{
			SpaceFamilyDataReader spaceFamilyDataReader = new SpaceFamilyDataReader();
			this.id = 0;
			if (this.listname.Count > 0)
			{
				foreach (ListItem listItem in this.listname)
				{
					if (this.lbfname.Text.Trim() == listItem.Name)
					{
						this.id = int.Parse(listItem.Tag.ToString());
					}
				}
			}
			foreach (ListItem listItem2 in spaceFamilyDataReader.GetInfoById("Sprinkler", this.id))
			{
				if (listItem2.Name == "Image")
				{
					if (File.Exists(listItem2.Value))
					{
						this.picbox.Image = new Bitmap(listItem2.Value);
					}
					else
					{
						this.picbox.Image = null;
					}
				}
				else if (listItem2.Name == "FamilySymbol")
				{
					this.UptadaFamilySybol(listItem2.Value);
				}
				else if (listItem2.Name == "RadiuDiameter")
				{
					this.tbRadius.Text = listItem2.Value;
				}
				else if (listItem2.Name == "KCoefficient")
				{
					this.tbK.Text = listItem2.Value;
				}
			}
		}

		private void rdoLimitDistance2_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoLimitDistance2.Checked)
			{
				this.panel1.Visible = false;
				this.panel2.Visible = true;
				this.cbJianju.Enabled = true;
			}
			this.UpdataCheckStatic();
		}

		private void rdoLimitNumber2_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoLimitNumber2.Checked)
			{
				this.panel1.Visible = true;
				this.panel2.Visible = false;
				this.cbJianju.Enabled = false;
			}
			this.UpdataCheckStatic();
		}

		public bool GetFormDataForJuXing()
		{
			string limitStr = "1";
			if (this.rdoLimitNumber2.Checked)
			{
				if (!(this.hytbRowCount.Text.Trim() != "") || !(this.hytbColCount.Text.Trim() != "") || !(this.hytbRatio2.Text.Trim() != ""))
				{
					YJKMessageBox.Show("参数不能为空");
					return false;
				}
				this.layAreaParameter.LimitFlag = 1;
				this.layAreaParameter.RowCount = Convert.ToInt32(this.hytbRowCount.Text.Trim());
				this.layAreaParameter.ColCount = Convert.ToInt32(this.hytbColCount.Text.Trim());
				this.layAreaParameter.Ratio = Convert.ToDouble(this.hytbRatio2.Text.Trim());
				limitStr = "1";
			}
			else if (this.rdoLimitDistance2.Checked)
			{
				if (!this.IsInputNorm())
				{
					return false;
				}
				this.layAreaParameter.LimitFlag = 2;
				this.layAreaParameter.RowDistance = Convert.ToDouble(this.hytbRowDistance.Text.Trim());
				this.layAreaParameter.ColDistance = Convert.ToDouble(this.hytbColDistance.Text.Trim());
				this.layAreaParameter.RowDistanceSide = Convert.ToDouble(this.hytbRowDistanceSide.Text.Trim());
				this.layAreaParameter.ColDistanceSide = Convert.ToDouble(this.hytbColDistanceSide.Text.Trim());
				this.layAreaParameter.LessDistance = double.Parse(this.hytbSmallDistance.Text.Trim());
				this.layAreaParameter.Danger = this.cmbDanger.Text;
				limitStr = "2";
			}
			this.LaySettingWriteJuXing(limitStr);
			return true;
		}

		private bool IsInputNorm()
		{
			bool result = true;
			if (this.IsTextBoxEmpty(this.hytbColDistance))
			{
				result = false;
			}
			else if (this.IsTextBoxEmpty(this.hytbRowDistance))
			{
				result = false;
			}
			else if (this.IsTextBoxEmpty(this.hytbRowDistanceSide))
			{
				result = false;
			}
			else if (this.IsTextBoxEmpty(this.hytbColDistanceSide))
			{
				result = false;
			}
			else if (this.IsTextBoxEmpty(this.hytbSmallDistance))
			{
				result = false;
			}
			else if (!this.IsTextBoxNumber(this.hytbColDistance))
			{
				result = false;
			}
			else if (!this.IsTextBoxNumber(this.hytbRowDistance))
			{
				result = false;
			}
			else if (!this.IsTextBoxNumber(this.hytbRowDistanceSide))
			{
				result = false;
			}
			else if (!this.IsTextBoxNumber(this.hytbColDistanceSide))
			{
				result = false;
			}
			else if (!this.IsTextBoxNumber(this.hytbSmallDistance))
			{
				result = false;
			}
			return result;
		}

		private bool IsTextBoxEmpty(System.Windows.Forms.TextBox tb)
		{
			bool result = false;
			if (tb.Text.Trim() == "")
			{
				result = true;
				YJKMessageBox.Information("所有参数均不能为空");
				tb.Focus();
			}
			return result;
		}

		private bool IsTextBoxNumber(System.Windows.Forms.TextBox tb)
		{
			bool flag = true;
			try
			{
				if (Convert.ToDouble(tb.Text.Trim()) <= 0.0)
				{
					YJKMessageBox.Information("所有参数均为正数");
					flag = false;
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Information("所有参数均为数字");
				flag = false;
			}
			if (!flag)
			{
				tb.Text = "";
				tb.Focus();
			}
			return flag;
		}

		private void LaySettingInitJuXing()
		{
			this.cmbDanger.Text = this.layAreaParameter.Danger;
			this.layAreaParameter = this.userSettingS.GetLaySprinklersArea();
			this.hytbRowCount.Text = this.layAreaParameter.RowCount.ToString();
			this.hytbColCount.Text = this.layAreaParameter.ColCount.ToString();
			this.hytbRatio2.Text = this.layAreaParameter.Ratio.ToString();
			this.hytbRowDistance.Text = this.layAreaParameter.RowDistance.ToString();
			this.hytbColDistance.Text = this.layAreaParameter.ColDistance.ToString();
			this.hytbRowDistanceSide.Text = this.layAreaParameter.RowDistanceSide.ToString();
			this.hytbColDistanceSide.Text = this.layAreaParameter.ColDistanceSide.ToString();
			if (this.layAreaParameter.LimitFlag.ToString() == "2")
			{
				this.rdoLimitDistance2.Checked = true;
				this.rdoLimitNumber2.Checked = false;
				return;
			}
			this.rdoLimitNumber2.Checked = true;
			this.rdoLimitDistance2.Checked = false;
		}

		private void LaySettingWriteJuXing(string limitStr)
		{
			this.userSettingS.WriteLaySprinklersArea(this.layAreaParameter);
		}

		private void InitCmbDanger()
		{
			this.cmbDanger.Items.Clear();
			this.cmbDanger.DisplayMember = "Name";
			this.cmbDanger.ValueMember = "MoreDistanceRow";
			this.cmbDanger.Items.Add(new DangerItem("轻危险等级", 4400.0, 4400.0, 2400.0, 2200.0, 2200.0, 3100.0));
			this.cmbDanger.Items.Add(new DangerItem("中危险等级I", 3600.0, 3600.0, 2400.0, 1800.0, 1800.0, 2500.0));
			this.cmbDanger.Items.Add(new DangerItem("中危险等级II", 3400.0, 3400.0, 2400.0, 1700.0, 1700.0, 2400.0));
			this.cmbDanger.Items.Add(new DangerItem("严重危险等级I", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.cmbDanger.Items.Add(new DangerItem("严重危险等级II", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.cmbDanger.Items.Add(new DangerItem("仓库危险等级I", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.cmbDanger.Items.Add(new DangerItem("仓库危险等级II", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			this.cmbDanger.Items.Add(new DangerItem("仓库危险等级III", 3000.0, 3000.0, 2400.0, 1500.0, 1500.0, 2100.0));
			int num = 0;
			string value = new UserSetting().GetValue("sprinklersRetangle", "danger");
			IEnumerator enumerator = this.cmbDanger.Items.GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					if ((enumerator.Current as DangerItem).Name == value)
					{
						break;
					}
					num++;
				}
			}
			if (num < 0 || num >= this.cmbDanger.Items.Count - 1)
			{
				num = 0;
			}
			this.cmbDanger.SelectedIndex = num;
			List<Element> elementByClass = YJKElementFilter.GetElementByClass(typeof(PipeType), this.doc);
			List<string> list = new List<string>();
			list = YJKElementFilter.GetElementNameByClass(typeof(PipingSystemType), this.doc);
			List<string> list2 = new List<string>();
			foreach (Element element in elementByClass)
			{
				this.cbxPipeType.Items.Add(element.Name);
				list2.Add(element.Name);
			}
			this.AdaptiveComboBoxDrawWith(this.cbxPipeType, list2);
			foreach (string item in list)
			{
				this.cmbSystemType.Items.Add(item);
			}
			try
			{
				this.cbxPipeType.SelectedIndex = 8;
			}
			catch (Exception)
			{
				this.cbxPipeType.SelectedIndex = 0;
			}
		}

		private void cmbDanger_SelectedIndexChanged(object sender, EventArgs e)
		{
			DangerItem dangerItem = this.cmbDanger.SelectedItem as DangerItem;
			this.hytbRowDistance.Text = dangerItem.MoreDistanceRow.ToString();
			this.hytbColDistance.Text = dangerItem.MoreDistanceCol.ToString();
			this.hytbSmallDistance.Text = dangerItem.LessDistance.ToString();
			this.hytbRowDistanceSide.Text = dangerItem.SideDistanceRow.ToString();
			this.hytbColDistanceSide.Text = dangerItem.SideDistanceCol.ToString();
		}

		private void hytbRowDistance_TextChanged(object sender, EventArgs e)
		{
			this.ChangeForeColor(this.hytbRowDistance, 10.0, 10000.0);
		}

		private void hytbColDistance_TextChanged(object sender, EventArgs e)
		{
			this.ChangeForeColor(this.hytbColDistance, 10.0, 10000.0);
		}

		private void hytbSmallDistance_TextChanged(object sender, EventArgs e)
		{
			this.ChangeForeColor(this.hytbSmallDistance, 10.0, 10000.0);
		}

		private void hytbRowDistanceSide_TextChanged(object sender, EventArgs e)
		{
			this.ChangeForeColor(this.hytbRowDistanceSide, 0.0, 10000.0);
		}

		private void hytbColDistanceSide_TextChanged(object sender, EventArgs e)
		{
			this.ChangeForeColor(this.hytbColDistanceSide, 0.0, 10000.0);
		}

		private void ChangeForeColor(System.Windows.Forms.TextBox tb, double min, double max)
		{
			try
			{
				if (Convert.ToDouble(tb.Text) < min || Convert.ToDouble(tb.Text) > max)
				{
					tb.ForeColor = System.Drawing.Color.Red;
				}
				else
				{
					tb.ForeColor = System.Drawing.Color.Black;
				}
			}
			catch (Exception)
			{
			}
		}

		private void hytbRowDistance_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '.' || e.KeyChar == '.')
			{
				string text = ((System.Windows.Forms.TextBox)sender).Text;
				for (int i = 0; i < text.Length; i++)
				{
					if (text[i] == '.')
					{
						e.Handled = true;
						return;
					}
				}
			}
			if (!StringTools.IsNumber(e.KeyChar))
			{
				e.Handled = true;
				return;
			}
			e.Handled = false;
		}

		private void label4_Click(object sender, EventArgs e)
		{
		}

		private void rdoHorizontal_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoHorizontal.Checked)
			{
				this.cbxPipeType.Enabled = true;
				this.cmbSystemType.Enabled = true;
				this.familyConnStyle = 1;
				if (this.familyCategory != 5)
				{
					this.tbDistance.Enabled = true;
					return;
				}
				this.tbDistance.Enabled = false;
			}
		}

		private void rdoVertical_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoVertical.Checked)
			{
				this.cbxPipeType.Enabled = true;
				this.cmbSystemType.Enabled = true;
				this.familyConnStyle = 2;
				if (this.familyCategory != 5)
				{
					this.tbDistance.Enabled = true;
					return;
				}
				this.tbDistance.Enabled = false;
			}
		}

		private void rdoNone_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoNone.Checked)
			{
				this.familyConnStyle = 3;
				this.tbDistance.Enabled = false;
				this.cbxPipeType.Enabled = false;
				this.cmbSystemType.Enabled = false;
			}
		}

		private void chkParking_CheckedChanged(object sender, EventArgs e)
		{
			this.isParking = this.chkParking.Checked;
			if (this.isParking || this.isBeams)
			{
				this.btnLX.Enabled = false;
				return;
			}
			this.btnLX.Enabled = true;
		}

		private void chkColumns_CheckedChanged(object sender, EventArgs e)
		{
			this.isAvoidColumns = this.chkColumns.Checked;
		}

		private void btnReplace_Click(object sender, EventArgs e)
		{
			this.layTerminalType = 6;
			this.sprinklersPara = new SprinklersParam();
			this.sprinklersPara.SymbolName = this.lbSymbol.SelectedItem.ToString();
			this.sprinklersPara.Id = this.id;
			base.DialogResult = DialogResult.OK;
		}

		private void chkBeams_CheckedChanged(object sender, EventArgs e)
		{
			this.isBeams = this.chkBeams.Checked;
			if (this.isBeams || this.isParking)
			{
				this.btnLX.Enabled = false;
				return;
			}
			this.btnLX.Enabled = true;
		}

		private void GetRectLayParas()
		{
			this.rectParas = new RectLayParamers();
			this.rectParas.LayType = Convert.ToInt32(!this.rdoLimitNumber2.Checked);
			this.rectParas.BeiShu = int.Parse(this.cbJianju.Text.ToString());
			this.rectParas.RowCount = Convert.ToInt32(this.hytbRowCount.Text.Trim());
			this.rectParas.ColCount = Convert.ToInt32(this.hytbColCount.Text.Trim());
			this.rectParas.Margin = Convert.ToDouble(this.hytbRatio2.Text.Trim());
			this.rectParas.XSpace = Convert.ToDouble(this.hytbRowDistance.Text.Trim());
			this.rectParas.YSpace = Convert.ToDouble(this.hytbColDistance.Text.Trim());
			this.rectParas.XMargin = Convert.ToDouble(this.hytbRowDistanceSide.Text.Trim());
			this.rectParas.YMargin = Convert.ToDouble(this.hytbColDistanceSide.Text.Trim());
			this.rectParas.LessDistance = double.Parse(this.hytbSmallDistance.Text.Trim());
			this.rectParas.AngleRow = Convert.ToDouble(this.hytbRowAngle.Text.Trim());
		}

		private void UpdataCheckStatic()
		{
			if (this.rdoLimitDistance2.Checked)
			{
				this.chkBeams.Enabled = true;
				this.chkParking.Enabled = true;
				this.chkColumns.Enabled = false;
				return;
			}
			this.chkBeams.Enabled = false;
			this.chkParking.Enabled = true;
			this.chkColumns.Enabled = false;
		}

		private void btnExplain_Click(object sender, EventArgs e)
		{
			MessageBox.Show("1.如果按照梁窝布置了喷头，则不再考虑车位;" + "\n2.如果识别车位，则会尽力将每个车位上方有喷头，但要兼顾行列间距;", "盈建科提示");
		}

		private void tvwProject_AfterSelect(object sender, TreeViewEventArgs e)
		{
			if (this.tvwProject.SelectedNode == null)
			{
				return;
			}
			this.tvwProject.SelectedNode.BackColor = System.Drawing.Color.DodgerBlue;
			this.tvwProject.SelectedNode.ForeColor = System.Drawing.Color.White;
			if (this.tvwProject.SelectedNode.Level == 0)
			{
				this.lbSymbol.Items.Clear();
				return;
			}
			Family family = this.tvwProject.SelectedNode.Tag as Family;
			this.lbSymbol.Items.Clear();
			this.fsList.Clear();
			this.fsList = family.GetSymbols();
			if (this.fsList.Count < 1)
			{
				return;
			}
			foreach (FamilySymbol familySymbol in this.fsList)
			{
				this.lbSymbol.Items.Add(familySymbol.Name);
			}
			this.lbSymbol.SelectedIndex = 0;
		}

		private void tvwProject_BeforeSelect(object sender, TreeViewCancelEventArgs e)
		{
			if (this.tvwProject.SelectedNode != null)
			{
				this.tvwProject.SelectedNode.BackColor = System.Drawing.Color.White;
				this.tvwProject.SelectedNode.ForeColor = System.Drawing.Color.Black;
			}
		}

		private void btnHy_Click(object sender, EventArgs e)
		{
			this.LbfnameTextChanged();
			this.btnHy.BackColor = System.Drawing.Color.White;
			this.currentBtn = 0;
			this.btnproj.BackColor = System.Drawing.Color.Transparent;
			this.panelHy.Visible = true;
			this.panelProj.Visible = false;
		}

		private void btnproj_Click(object sender, EventArgs e)
		{
			this.btnHy.BackColor = System.Drawing.Color.Transparent;
			this.currentBtn = 1;
			this.btnproj.BackColor = System.Drawing.Color.White;
			this.panelHy.Visible = false;
			this.panelProj.Visible = true;
			if (this.tvwProject.SelectedNode != null)
			{
				if (this.tvwProject.SelectedNode == this.tvwProject.TopNode)
				{
					this.lbSymbol.Items.Clear();
					return;
				}
				TreeNode selectedNode = this.tvwProject.SelectedNode;
				this.tvwProject.SelectedNode = this.tvwProject.Nodes[0];
				if (this.tvwProject.Nodes[0].Nodes.Count < 1)
				{
					return;
				}
				this.tvwProject.SelectedNode = selectedNode;
				return;
			}
			else
			{
				this.tvwProject.SelectedNode = this.tvwProject.Nodes[0];
				if (this.tvwProject.Nodes[0].Nodes.Count < 1)
				{
					return;
				}
				this.tvwProject.SelectedNode = this.tvwProject.Nodes[0].Nodes[0];
				return;
			}
		}

		private void lbSymbol_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.currentBtn == 1)
			{
				this.Fsymbol = this.fsList.FirstOrDefault((FamilySymbol q) => q.Name == this.lbSymbol.SelectedItem.ToString());
			}
		}

		private void AdaptiveComboBoxDrawWith(System.Windows.Forms.ComboBox box, List<string> ItemContants)
		{
			int num = 0;
			Graphics graphics = base.CreateGraphics();
			foreach (string text in ItemContants)
			{
				SizeF sizeF = graphics.MeasureString(text, box.Font);
				if (num < (int)sizeF.Width)
				{
					num = (int)sizeF.Width;
				}
			}
			if (box.DropDownWidth < num)
			{
				box.DropDownWidth = num + 20;
			}
		}

		public int layTerminalType;

		public SprinklersParam sprinklersPara;

		public LayAreaParameter layAreaParameter = new LayAreaParameter();

		private HVACUserSetting userSettingS = new HVACUserSetting();

		private List<ListItem> listInfos = new List<ListItem>();

		private string name = "";

		public int familyCategory = 1;

		public int familyConnStyle = 1;

		public bool isThreePointLay;

		public bool isParking;

		private string familyName = "";

		private string familySymbol = "";

		public bool isAvoidColumns;

		public bool isBeams;

		private int id;

		private List<ListItem> listname = new List<ListItem>();

		private Document doc;

		public RectLayParamers rectParas;

		private int currentBtn;

		private List<FamilySymbol> fsList = new List<FamilySymbol>();

		private SpaceFamilyDataReader sfdr = new SpaceFamilyDataReader();
	}
}
